package cn.example.vip.mall.seckill.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

public class RedisLock {
	@Value("${spring.redis.host}:${spring.redis.port}")
	private String host;
	
	/**
	 * 1.创建锁,2.解锁
	 */
	@Bean
	public RedissonClient redisClient(){
		// 创建 Config 对象
		Config config = new Config();
//		config.useClusterServers().setScanInterval(2000/*扫描周期*/).addNodeAddress("地址"); // 集群
		config.useSingleServer().setAddress("redis://" + host);	// 单机
		// 创建 RedisClient
		return Redisson.create(config);
	}
}
